﻿<cfsilent>
	<cfscript>
		
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");
		
		subjectId = event.getArg("SBJ");
		grade = event.getArg("GRD");
		studentId = event.getArg("STU");
		
		/*查询学生的修读专业信息*/
		sql = "	SELECT
					stu.stu_id, clz.grade, sbj.sbj_id, stu.sbj_direction
				FROM
					t_student stu INNER JOIN t_class clz ON stu.cls_id = clz.cls_id INNER JOIN t_subject sbj ON clz.sbj_id = sbj.sbj_id
				WHERE
					stu.stu_id = :studentId ";

		queryObj = new Query( datasource=application.dnsMaster );

		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );

		rs_student_subject = queryObj.execute( sql=sql ).getResult();


		/* 学生成绩明细 */
		sql = "SELECT 
						b.cid, b.course_name, b.course_credit, a.credit_point, 
						a.scm_id, 
						a.retaking, a.mark_mode, 
						a.mark_result, a.mark_note, 
						a.mark_resit, a.mark_renote, a.mark_resit_limit, 
						c.prop_name 
					FROM t_student_mark a 
						 INNER JOIN t_course b ON b.cid = a.cid 
						 INNER JOIN t_course_prop c ON c.prop_id = a.prop_id 
					WHERE 
						  a.stu_id = :studentId 
						  AND 
						  b.cid IN (	SELECT
												s.cid
											FROM
												t_schema s
											WHERE
												s.grade = :grade 
												AND
												(s.sbj_id = :subjectId OR s.sbj_id = :subjectDir )
												AND
												SUBSTR(s.shm_prop,1,1) = '1' 
							)  
					ORDER BY b.course_name ";
		
		
		queryObj = new Query( datasource=application.dnsSlave );
		
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="grade", value=rs_student_subject.grade, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="subjectId", value=rs_student_subject.sbj_id, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="subjectDir", value=rs_student_subject.sbj_id & rs_student_subject.sbj_direction, cfsqltype="cf_sql_varchar" );
			
		rs_mark = queryObj.execute( sql=sql ).getResult();
		
		/* 读取尚需完成的学位课 */
		sql = "SELECT 
					DISTINCT b.cid, b.course_name , b.course_credit  
					FROM t_mark_need a 
						INNER JOIN t_course b ON b.cid = a.cid 
					WHERE 
						  a.stu_id = :studentId 
						  AND 
						  (a.gdc = 'CPD' OR a.gdc = 'CBD')
					ORDER BY b.course_name ";
							
		queryObj = new Query( datasource=application.dnsSlave );

		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );

		rs_mark_need = queryObj.execute( sql=sql ).getResult();
		
		
		/* 读取通过课程 */
		sql = "SELECT *
					FROM query
					WHERE credit_point > 0  ";
							
		queryObj = new Query( dbtype="query" );
		queryObj.setAttributes( query=rs_mark );

		rs_pass = queryObj.execute( sql=sql ).getResult();
	
		
		/* 读取标注替代的课程 */
		sql = "SELECT stu_crp, a.course_name course_name_a, b.course_name course_name_b 
					FROM t_student_course_replace s 
						INNER JOIN t_course a ON a.cid = s.cid_a 
						INNER JOIN t_course b ON b.cid = s.cid_b 
					WHERE 
						stu_id = :studentId 
						AND 
						a.cid IN (
								SELECT
									s.cid
								FROM
									t_schema s
								WHERE
									s.grade = :grade 
									AND
									(s.sbj_id = :subjectId OR s.sbj_id = :subjectDir )
									AND
									SUBSTR(s.shm_prop,1,1) = '1'
						)";

		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="grade", value=rs_student_subject.grade, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="subjectId", value=rs_student_subject.sbj_id, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="subjectDir", value=rs_student_subject.sbj_id & rs_student_subject.sbj_direction, cfsqltype="cf_sql_varchar" );

		rs_replace = queryObj.execute( sql=sql ).getResult();
			
		passArgs = structNew();
		structInsert( passArgs, "SBJ", subjectId, true );
		structInsert( passArgs, "GRD", grade, true );
		structInsert( passArgs, "STU", studentId, true );
		structInsert( passArgs, "SBJ_DIR", rs_student_subject.sbj_direction, true );

	</cfscript>
</cfsilent>

					<div class="noticeBlock">
						<h3>成绩数据明细</h3>
						<hr/>
					</div>
					
					<div class="UIColumns">
						
						<div class="col2 first">
							
							<div class="noticeBlock">
								<h2 class="UILeadHead markPassed"><span>已通过课程</span></h2>
							</div>
							
							<!--- 已通过课程 --->
							<table class="UItable markPassed">
								
								<tr class="cellDivide cellHeader">
									<td>课程</td>
									<td width="30">学分</td>
									<td width="30">成绩</td>
								</tr>
								
								<tbody>
									<cfloop query="rs_pass">

										<cfset markFinal = markAdvice.getMarkResult( rs_pass.mark_mode, rs_pass.mark_result, rs_pass.mark_note, rs_pass.mark_resit, rs_pass.mark_renote, rs_pass.mark_resit_limit ) />
										<tr class="cellDivide">
											<td><cfoutput>#rs_pass.course_name#</cfoutput></td>
											<td align="center"><span class="number"><cfoutput>#numberFormat( rs_pass.course_credit, "_.__" )#</cfoutput></span></td>
											<td align="center">
												<cfif isNumeric(markFinal)>
														<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
													<cfelse>
														<cfoutput>#markFinal#</cfoutput>
												</cfif>
											</td>
										</tr>
									</cfloop>
								</tbody>
								
							</table>
							
						</div>
						
						<div class="col2 last">
							
							<cfif rs_mark_need.recordCount>
								
								<div class="noticeBlock">
									<h2 class="UILeadHead markNeed"><span>尚需完成的学位课</span></h2>
								</div>
								
								<!--- 培养方案规定的学位课 --->	
								<table class="UItable markNeed">
									
									<tr class="cellDivide cellHeader">
										<td>课程</td>
										<td width="30">学分</td>
										<td width="18"></td>
									</tr>
									
									<tbody>
										<cfloop query="rs_mark_need">
											
											<cfset structInsert( passArgs, "CID", rs_mark_need.cid, true ) />
											
											<tr class="cellDivide">
												<td><cfoutput>#rs_mark_need.course_name#</cfoutput></td>
												<td align="center"><span class="number"><cfoutput>#numberFormat( rs_mark_need.course_credit, "_.__" )#</cfoutput></span></td>
												<td><a title="指定替代课程" href="<cfoutput>#buildURL('signDegreeCourseReplace', passArgs)#</cfoutput>" class="operation linkCourse"></a></td>
											</tr>
								
										</cfloop>
										<!--- 移除额外参数 --->
										<cfset structDelete( passArgs, "CID", false ) />
									</tbody>
								
								</table>
								
							</cfif>
			
							
							<cfif rs_replace.recordCount>
								
								<div class="noticeBlock">
									<h2 class="UILeadHead markReplace"><span>标注替换课程</span></h2>
								</div>
								
								<!--- 已替换课程 --->	
								<table class="UItable markReplace">
									
									<tr class="cellDivide cellHeader">
										<td>课程</td>
									</tr>
								
									<tbody>
										<cfloop query="rs_replace">
										
											<cfset structInsert( passArgs, "SUTCRP", rs_replace.stu_crp, true ) />
											<tr class="cellDivide">
												<td><cfoutput>#rs_replace.course_name_a#</cfoutput> 由 <cfoutput>#rs_replace.course_name_b# 替代</cfoutput></td>
											</tr>
										
										</cfloop>
										<!--- 移除额外参数 --->
										<cfset structDelete( passArgs, "SCMID", false ) />
									</tbody>
								
								</table>
								
							</cfif>
							
						</div>
						
					</div>
					